<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>6.认识一下VueComponent</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo"></div>

    <script type="text/javascript">
      // 创建一个人的组件
      let Person = Vue.extend({
        name:'Person',
        template:`
          <div>
            <h2>名字：{{name}}</h2>  
            <h2>年龄：{{age}}</h2>
            <button @click="showPerson">点我展示人员信息</button>  
          </div>
        `,
        data(){
          return {
            name:'tony',
            age:18
          }
        },
        methods:{
          showPerson(){
            console.log(this)
            alert(`我叫${this.name}，今天我${this.age}岁了`)
          }
        }
      })

      let School = Vue.extend({
        name:'School',
        template:`
          <div>
            <h1>学校信息</h1>
            <h3>校名：{{schoolName}}</h3>
            <h3>地址：{{schoolAddress}}</h3>
            <button @click="showSchool">点我提示学校信息</button>
          </div>
        `,
        data(){
          return {
            schoolName:'尚硅谷',
            schoolAddress:'宏福科技园'
          }
        },
        methods:{
          showSchool(){
            alert(`${this.schoolName}坐落于${this.schoolAddress}`)
          }
        }
      })

      let App = Vue.extend({
        name:'App',
        components:{Person,School},
        template:`
          <div>
            <Person/>
            <hr>
            <School/>
          </div>
        `
      })

      // console.log(Person) //输出的是VueComponent构造函数，包含着人相关的配置
      // console.log(School) //输出的是VueComponent构造函数，包含着学校相关的配置
      // console.log(App) //输出的是VueComponent构造函数，包含着欢迎相关的配置

      let vm = new Vue({
        el:'#demo',
        components:{App},
        template:`<App/>`
      })

      console.log(vm)
    </script>
  </body>
</html>